package com.framework.tomcat;

import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
//import org.apache.catalina.startup.Tomcat;
import org.apache.naming.factory.Constants;

import javax.naming.InitialContext;
import javax.naming.spi.ObjectFactory;
import java.util.Hashtable;

/**
 * 嵌入式启动Tomcat
 * 
 * @author Administrator
 * @date 20191117
 */
public class Application {
	public static void main(String[] args) throws LifecycleException {
//		Tomcat tomcat = new Tomcat();
//		HttpServlet servlet = new HttpServlet() {
//			public void service(ServletRequest request, ServletResponse response)
//				throws ServletException,IOException{
//				response.getWriter().write("Hello World");
//			}
//		};
//		Context context = tomcat.addContext("/sample",null);
		//Context context = tomcat.addContext("/", "D:\\Eclipse\\eclipse-workspace\\apache-tomcat\\apache-tomcat-8.5.32\\conf\\context.xml");
		try {
			Hashtable<String, Object> contextEnv = new Hashtable<>();
			
			InitialContext InitialContext = new InitialContext();
			String javaxSqlDataSourceFactoryClassName =
                    System.getProperty("javax.sql.DataSource.Factory",
                    		Constants.DBCP_DATASOURCE_FACTORY);
			ObjectFactory factory = (ObjectFactory)
                        Class.forName(javaxSqlDataSourceFactoryClassName)
                        .newInstance();
		} catch (Exception e1) {
			e1.printStackTrace();
		}
//		Tomcat.addServlet(context, "/servlet", servlet);
		try {
			//tomcat.addWebapp("/project", "D:\\Eclipse\\eclipse-workspace\\apache-tomcat\\apache-tomcat-8.5.32\\webapps\\project_dev");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//		context.addServletMapping("/servlet","/servlet");
		
//		tomcat.init();
//		tomcat.start();
//		tomcat.getServer().await();//用于阻塞主程序结束，视实际情况确定是否需要
		
		
	}
}
